package com.example.shopping.controller;

import lombok.Builder;
import lombok.Getter;

import java.io.Serializable;

/**
 * @author duoliang.zhang
 * @since 2021/6/26 9:56
 */
@Getter
@Builder
public class Result<T> implements Serializable {
    private final boolean success;
    private final int code;
    private final String message;
    private final T data;

    private Result(boolean success, int code, String message, T data) {
        this.success = success;
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static <T> Result<T> success(T data) {
        return new Result<>(true, 1, "", data);
    }

    public static <T> Result<T> success() {
        return new Result<>(true, 1, "", null);
    }

    public static <T> Result<T> failure() {
        return new Result<>(false, 0, "", null);
    }
}
